@extends('admin.layout.layout', ['row' => @$page])

@section('contain')


    <div class="portlet">
        <div class="portlet-title">
            <div class="caption">
                <x-portlet-breadcrumb :page="$page"></x-portlet-breadcrumb>
            </div>
            <div class="actions">
                <div class="item">
                    <a href="/{{ request()->path() }}/download_template" class="btn btn-sm btn-primary">{{ ts('DOWNLOADTEMPLATE') }}</a>
                </div>
                <div class="item">
                    <a href="/{{ request()->path() }}/bulk_import" class="btn btn-sm btn-primary">{{ ts('BULKIMPORT') }}</a>
                </div>
                <div class="item">
                    <a href="/{{ request()->path() }}/create" class="btn btn-sm btn-primary">{{ ts('addnew') }}</a>
                </div>
            </div>
        </div>

        <div class="filter-wrapper">
            <form action="/{{ request()->path() }}/" class="form-inline filter-form">
                <div class=" input-group mb-3 custom-control-inline">
                    <div class="input-group-prepend">
                        <select name="label" class="form-control">
                            <option value="id" {{ request()->input('label') == 'id' ? 'selected' : '' }}>{{ ts('warrantyid') }}</option>
                            <option value="first_name" {{ request()->input('label') == 'first_name' ? 'selected' : '' }}>{{ ts('CUSTOMERNAME') }}</option>
                            <option value="installer_name" {{ request()->input('label') == 'installer_name' ? 'selected' : '' }}>{{ ts('installername') }}</option>
                            <option value="license_plate" {{ request()->input('label') == 'license_plate' ? 'selected' : '' }}>{{ ts('LICENSEPLATE') }}</option>
                        </select>
                    </div>
                    <input type="text" class="form-control" name="value" value="{{ request()->input('value') }}">
                </div>
                <x-flatpickr-date-range></x-flatpickr-date-range>
                <div class="mb-3">
                    <button class="btn btn-primary">{{ ts('SEARCH') }}</button>
                    <a href="/{{ request()->path() }}/" class="btn btn-warning">{{ ts('RESET') }}</a>
                </div>

            </form>
        </div>

        <div>
            <table class="table table-s1">
                <thead>
                <tr class="order_column">
                    <th style="width: 50px;"></th>
                    <th style="width: 75px;">{{ ts('sequence') }}</th>
                    <th style="width: 100px;" data-column="id">{{ ts('warrantyid') }}</th>
                    <th style="width: 150px;">{{ ts('ROLLID') }}</th>
                    <th style="width: 200px;" data-column="license_plate">{{ ts('licenseplate') }}</th>
                    <th style="width: 100px;">{{ ts('length') }}</th>
                    <th style="width: 100px;" data-column="installation_date">{{ ts('installationdate') }}</th>
                    <th style="width: 150px;" data-column="installer_name">{{ ts('INSTALLERNAME') }}</th>
                    <th data-column="company_name">{{ ts('dealer') }}</th>
                    <th style="width: 100px;">{{ ts('status') }}</th>
                    <th style="width:270px">{{ ts('OPTION') }}</th>
                </tr>
                </thead>
                <tbody>
                @foreach($data as $k => $v)
                    <tr class="item-list">
                        <td class="text-center">
                            <input type="checkbox" class="warranty_icheck icheck_input" name="ids[]" value="{{ $v->id }}">
                        </td>
                        <td class="text-center">
                            <div class="truncated-3">{{ @$data->firstItem()+$k }}</div>
                        </td>
                        <td>
                            <div class="truncated-3">{{ @$v->id }}</div>
                        </td>
                        <td>
                            @foreach(@$v->warranty_to_vehicle_coverage as $r)
                                <div>{{ @$r->roll_number }}：{{ @$r->length }}</div>
                            @endforeach
                        </td>
                        <td>
                            <div class="truncated-3">{{ @$v->license_plate }}</div>
                        </td>
                        <td>
                            <div class="truncated-3">{{ array_sum(\Illuminate\Support\Arr::pluck(@$v->warranty_to_vehicle_coverage, 'length')) }}</div>
                        </td>
                        <td>
                            <div class="truncated-3">{{ $v->installation_date }}</div>
                        </td>
                        <td>
                            <div class="truncated-3">{{ $v->installer_name }}</div>
                        </td>
                        <td>
                            <div class="truncated-3">{{ @$v->company_name }}</div>
                            {{--<div class="truncated-3">{{ @$v->dealer->company_name }}</div>--}}
                        </td>
                        <td>
                            <div class="truncated-3">
                                @if($v->approved == 0)
                                    {{ ts('pending') }}
                                @elseif($v->approved == 1)
                                    {{ ts('granted') }}
                                @else
                                    {{ ts('reject') }}
                                @endif
                            </div>
                        </td>
                        <td>
                            <a class="btn btn-success btn-sm" href='/{{ request()->path() }}/{{ $v->id }}' target="_blank">{{ ts('VIEW') }}</a>
                            @if(session('admin.user_type')==1)
                                <a class="btn btn-warning btn-sm" href='/{{ request()->path() }}/{{ $v->id }}/edit' target="_blank">{{ ts('edit') }}</a>
                                <span class="btn btn-danger btn-sm" onclick="handleDelete({{ $v->id }})">{{ ts('delete') }}</span>
                            @endif
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>

            <div class="row my-3">
                <div class="col-auto">
                    <label style="cursor: pointer"><input type="checkbox" class="icheck_all" data-ele=".warranty_icheck"><span class="ml-2">{{ ts('SELECTALL') }}</span></label>
                    <span class="btn btn-primary ml-3" onclick="deleteAlliCheck('.warranty_icheck', '/admin/warranty/deletes')">{{ ts('delete') }}</span>
                </div>
                <div class="col">
                    {{ $data->appends(request()->input())->links() }}
                </div>
            </div>
        </div>

    </div>


@endsection